package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmy.cultivate.entity.EnrollInviteDetail;
import com.xmy.cultivate.entity.RecordCourse;
import com.xmy.cultivate.entity.Student;
import com.xmy.cultivate.mapper.EnrollInviteDetailMapper;
import com.xmy.cultivate.service.IEnrollInviteDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmy.cultivate.service.IRecordCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 邀约详情 服务实现类
 * </p>
 *
 * @author hpiggy
 * @since 2024-08-29
 */
@Service
public class EnrollInviteDetailServiceImpl extends ServiceImpl<EnrollInviteDetailMapper, EnrollInviteDetail> implements IEnrollInviteDetailService {

    @Autowired
    EnrollInviteDetailMapper enrollInviteDetailMapper;

    @Autowired
    IRecordCourseService iRecordCourseService;

    /**
     *
     */
    @Override
    public void updateSigin(Student student){
        LocalDate schoolDate = LocalDate.now();
        List<EnrollInviteDetail> enrollInviteDetailList = enrollInviteDetailMapper.getEnrollInviteDetailByInvitePhone(student.getLinkmanPhone().toString(),schoolDate.toString());
        for (EnrollInviteDetail enrollInviteDetail : enrollInviteDetailList) {
            QueryWrapper<RecordCourse> recordCourseQueryWrapper = new QueryWrapper<>();
            recordCourseQueryWrapper.eq("student_id", student.getId());
            recordCourseQueryWrapper.eq("course_type", 8);
            recordCourseQueryWrapper.eq("lesson_type", 1);
            recordCourseQueryWrapper.eq("school_date", schoolDate);
            List<RecordCourse> recordCourseList = iRecordCourseService.list(recordCourseQueryWrapper);
            for (RecordCourse recordCourse : recordCourseList) {
                if (enrollInviteDetail.getSchoolId().equals(recordCourse.getSchoolId())){
                    enrollInviteDetail.setIsSigin(1);
                    this.updateById(enrollInviteDetail);
                }
            }
        }
    }
}
